<!-- 模板 -->
<template>
  <div class="login">
    <div class="main">
      <div class="title">
        <div class="h1">
          <span>E</span>
          ast
          <span>D</span>
          ecision
        </div>
        <div class="h2">Fusion experimental data mining system</div>
      </div>
      <div class="from">
        <el-form
          :model="userInfo"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item class="e-item" label-width="auto" prop="name">
            <el-input
              v-model="userInfo.name"
              prefix-icon="el-icon-phone"
              placeholder="username"
            ></el-input
          ></el-form-item>
          <el-form-item class="e-item" label-width="auto" prop="passWord">
            <el-input
              v-model="userInfo.passWord"
              type="passWord"
              prefix-icon="el-icon-user-solid"
              :show-password="true"
              placeholder="userPassWord"
            ></el-input>
          </el-form-item>

          <el-checkbox v-model="checked">自动登录</el-checkbox>

          <el-form-item class="e-item item" label-width="auto">
            <el-button type="primary" @click="submitForm('ruleForm')"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="sign">Copyrightc2021 Institute of Plasma Physics</div>
  </div>
</template>
<script>
export default {
  data() {
    let validPassWord = (reg, value, next) => {
      reg = /^\w{6,12}$/;
      if (!reg.test(value)) {
        return next(new Error("密码使用英文、数字、下划线6-12位"));
      }
      next();
    };
    return {
      checked: false,
      userInfo: {
        name: "",
        passWord: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入用户名名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        passWord: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 12,
            message: "长度在 6 到 12 个字符",
            trigger: "blur",
          },
          { validator: validPassWord, trigger: "blur" },
        ],
      },
    };
  },
  props: [],
  components: {},
  computed: {},
  filters: {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        console.log(valid);
        if (!valid) {
          this.$router.push("/home");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="less" scoped>
.login {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  display: flex;
  align-items: center;
  flex-direction: column-reverse;
  justify-content: flex-start;
  .main {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    flex-direction: column;
    background: #fff;
    width: 500px;
    height: 400px;
    border-radius: 16px;
    .title {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      width: 380px;
      border-radius: 20px;
      background: #fff;

      .h1 {
        span {
          font-size: 26px;
          color: #ffcc33;
        }
        font-size: 20px;
        color: #0099cc;
      }
      .h2 {
        color: #0099cc;
        font-size: 18px;
      }
    }
  }
  .from {
    width: 380px;
    form {
      /deep/.el-input {
        input {
          // margin-bottom: 15px !important;
        }
        span {
          // top: -6px;
        }
        .el-form-item__error {
          top: 100% !important;
        }
      }

      button {
        width: 100%;
        background: #0099cc;
      }
      .item {
        margin-top: 20px;
      }
    }
  }
  .sign {
    font-size: 14px;
    color: #ccc;
    padding-bottom: 40px;
  }
}
// @import url(); 引入公共css类
</style>
